/*
 * @Author: ujjldn ujjldn0515@163.com
 * @Date: 2025-08-02 17:12:45
 * @LastEditors: ujjldn ujjldn0515@163.com
 * @LastEditTime: 2025-08-02 17:51:49
 * @FilePath: \g-dialog\vite.config.g-dialog.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// vite.config.g-dialog.js
import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import {resolve} from 'node:path'

export default defineConfig({
  resolve: {
    alias: {
        "@": resolve(__dirname, 'src'),
    },
    extensions: ['.js', '.vue', '.json', '.ts']
  },
  define: {
    // 添加这一行来解决 process 未定义的问题
    'process.env': {},
    __VUE_OPTIONS_API__: 'true',
    __VUE_PROD_DEVTOOLS__: 'false'
  },
  build: {
    outDir: './dist',
    lib: {
      entry: './g-drawer.js',
      name: 'GDrawer',
      fileName: (format) => `g-drawer.${format}.js`
    },
    rollupOptions: {
      external: ['vue'],
      output: {
        globals: {
          vue: 'Vue'
        },
        assetFileNames: (assetInfo) => {
          if (assetInfo.name.endsWith('.css')) {
            return 'g-drawer.css';
          }
          return assetInfo.name;
        },
      }
    },
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      },
      format: {
        ascii_only: true
      }
    }
  },
  plugins: [vue()],
  esbuild: {
    charset: 'utf8'
  }
})